package jianzhi

func maxProfit(prices []int) int {
	res := 0

	if len(prices) == 0 {
		return res
	}

	min := prices[0]
	for i := range prices {
		temp := prices[i] - min
		if temp > res {
			res = temp
		}

		if prices[i] < min {
			min = prices[i]
		}
	}

	return res
}
